<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Config;

/**
 * Class DatabaseSeeder
 *
 * 数据库填充数据
 */
class AdminsSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $date = date('Y-m-d H:i:s');

        $route_prefix = '/' . Config::get('admin.route.prefix');


        // 添加一个超级管理员
        DB::table('admins')->insertGetId([
            'name'       => 'super',
            'email'      => 'super@admin.com',
            'password'   => bcrypt('admin123'),
            'status'     => 10,
            'created_at' => $date,
            'updated_at' => $date,
        ]);

        DB::table('admins')->insertGetId([
            'name'       => 'admin',
            'email'      => 'admin@admin.com',
            'password'   => bcrypt('admin888'),
            'status'     => 10,
            'created_at' => $date,
            'updated_at' => $date,
        ]);

        // 添加后台管理导航栏目
        $intParentId = DB::table('menus')->insertGetId([
            'name'       => '后台管理',
            'url'        => '#',
            'icon'       => 'fa-cogs',
            'parent'     => 0,
            'created_at' => $date,
            'updated_at' => $date,
        ]);

        // 添加菜单
        DB::table('menus')->insert([
            [
                'name'       => '管理员',
                'url'        => $route_prefix . '/admins/index',
                'icon'       => 'fa-user',
                'parent'     => $intParentId,
                'created_at' => $date,
                'updated_at' => $date,
            ],
            [
                'name'       => '导航栏目',
                'url'        => $route_prefix . '/menus/index',
                'icon'       => 'fa-bars',
                'parent'     => $intParentId,
                'created_at' => $date,
                'updated_at' => $date,
            ],
            [
                'name'       => '日程管理',
                'url'        => $route_prefix . '/calendars/index',
                'icon'       => 'fa-calendar',
                'parent'     => $intParentId,
                'created_at' => $date,
                'updated_at' => $date,
            ],
            [
                'name'       => '上传文件',
                'url'        => $route_prefix . '/uploads/index',
                'icon'       => 'fa-upload',
                'parent'     => $intParentId,
                'created_at' => $date,
                'updated_at' => $date,
            ],
        ]);

        DB::table('configs')->insert([
            'name'       => 'login',
            'config'     => json_encode([
                'private_key' => '-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCluWQF/r4+VZJHXcv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EY-----',
            ]),
            'created_at' => $date,
            'updated_at' => $date,
        ]);

        if (config('admin.verify_permissions')) {
            DB::table('menus')->insert([
                [
                    'name'       => '角色管理',
                    'url'        => '/admin/roles/index',
                    'icon'       => 'fa-magic',
                    'parent'     => $intParentId,
                    'created_at' => $date,
                    'updated_at' => $date,
                ],
                [
                    'name'       => '权限管理',
                    'url'        => '/admin/permissions/index',
                    'icon'       => 'fa-leaf',
                    'parent'     => $intParentId,
                    'created_at' => $date,
                    'updated_at' => $date,
                ],
                [
                    'name'       => '权限分配',
                    'url'        => '/admin/role-users/index',
                    'icon'       => 'fa-paper-plane',
                    'parent'     => $intParentId,
                    'created_at' => $date,
                    'updated_at' => $date,
                ],
            ]);

            // 添加角色
            DB::table(Config::get('entrust.roles_table'))->insertGetId([
                'name'         => 'superAdmin',
                'display_name' => '超级管理员',
                'description'  => '超级管理员',
                'created_at'   => $date,
                'updated_at'   => $date,
            ]);

            DB::table(Config::get('entrust.roles_table'))->insert([
                'name'         => 'admin',
                'display_name' => '普通管理员',
                'description'  => '普通管理员',
                'created_at'   => $date,
                'updated_at'   => $date,
            ]);
        }
    }
}
